体操队形
import java.util.;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i  n; i++) {
            arr[i] = in.nextInt();
        }
        int count = 0;
        boolean[] flag = new boolean[n];
        System.out.println(fun(arr, new int[n], flag, 0));
    }
    
    public static int fun(int[] arr, int[] tmp, boolean[] flag, int count) {
        int len = arr.length;
        if (count == len) {
            return 1;
        }
        int ret = 0;
        for (int i = 0; i  len; i++) {
            if (!flag[i]) {
                flag[i] = true;
                if (arr[i] == i+1) {
                    tmp[count] = i+1;
                    ret += fun(arr, tmp, flag, count+1);
                } else {
                    for (int j = 0; j  count; j++) {
                        if (tmp[j] == arr[i]) {
                            flag[i] = false;
                            return 0;
                        }
                    }
                    tmp[count] = i+1;
                    ret += fun(arr, tmp, flag, count+1);
                }
                flag[i] = false;
            }
        }
        return ret;
    }
}